package com.wan.data.resource.converter;

import cn.hutool.core.convert.Converter;
import com.wan.util.ObjectUtil;

/**
 * @author wwh
 * @date 2022/7/6 10:25
 */
public class StringArrayConverter implements Converter<String[]> {
    @Override
    public String[] convert(Object value, String[] defaultValue) throws IllegalArgumentException {
        String string = value.toString();
        if(ObjectUtil.isEmpty(string)){
            return new String[0];
        }
        char first = string.charAt(0);
        if(first == '['){
            string = string.substring(1);
        }
        char last = string.charAt(string.length() - 1);
        if(last == ']'){
            string = string.substring(0,string.length() - 1);
        }
        if (ObjectUtil.isEmpty(string)) {
            return new String[0];
        }
        return string.split(",");
    }
}
